<template>
	<view class="pt100 pd">
		<view class="fz32 cf">
			绑定联网号
		</view>
		<view class="fz28 cf mt10">
			请输入手机号{{phone}}接收到的验证码
		</view>
		<view class="pr mt60">
			<input type="text" value="" placeholder="请输入验证码" class="jhhgerttyt" v-model="code"/>
			<view class="saomhnseer z9 fz26 " :class="daojishi>0?'z9':'ls'" @tap="cjjseerr">
				重新获取<text v-if="daojishi>0">({{daojishi}}s)</text>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				isbianj: false,
				daojishi: 60,
				carid:"",
				network:"",
				license:"",
				phone:"",
				key:"",
				code:""
			}
		},
		components: {},
		onLoad(e) {	
			this.carid=e.carid
			this.network=e.net
			this.license=e.license
			console
			uni.setNavigationBarTitle({
				title:e.license
			});
			this.daojishise()
		},
		methods: {
			async daojishise() {
				var phone=this.$store.state.userinfo
				console.log("00",phone)				
				this.phone=phone.phone.replace(/(^1\d{2})(\d{4})(\d{4})/g,'$1****$3')
				let params={}
				params.phone=phone.phone
				let code=await this.post('/api/verificationCodes',params)
				console.log("验证码",code)
				this.key=code.key
				let hhhbgde = setInterval(a => {
					if(this.daojishi--<1){
						clearInterval(hhhbgde)
					}
				}, 1000)
			},
			cjjseerr(){
				if(this.daojishi>0){
					return
				}
				this.daojishi = 60
				this.daojishise()
			},
			async bind(){
				let params={}
				params.network=this.network
				params.verification_key=this.key
				params.verification_code=this.code
				let cbind=await this.get('/api/car/'+this.carid+'/bind',params,'PUT')
				console.log('绑定',cbind)
				if(cbind.code==0){
					uni.showToast({
						title:'绑定成功'
					})
					setTimeout(function(){
						uni.navigateBack({
							delta: 2
						})
					},2000)
				}
			}
		},
		onNavigationBarButtonTap() {
			if(this.code){
				this.bind()
			}
			// uni.switchTab({
			//     url: '/pages/index/index'
			// });
		},
		mounted() {}
	}
</script>
<style scoped>
	.saomhnseer{
		position: absolute;
		right: 140upx;
		top: 32upx;
		white-space:nowrap;
	}
</style>
